import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User:xieChao
 * Date:2022/10/31 19:18
 */
public class JdbcUpdate {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/java1?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("001110");

        Connection connection = dataSource.getConnection();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要修改的id：");
        int id = sc.nextInt();
        System.out.println("请输入要修改的age：");
        int age = sc.nextInt();
//        System.out.println("请输入要修改的age：");
//        int age = sc.nextInt();
//        System.out.println("请输入要修改的sroce：");
//        double sroce = sc.nextDouble();
        String sql = "update student set age = ? where id = ?";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1,age);
        statement.setInt(2,id);

        System.out.println("statement:"+statement);

        int ret = statement.executeUpdate();
        System.out.println(ret);

        statement.close();
        connection.close();

    }
}
